package com.kx.web;

import com.kx.model.User;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

@Controller
public class UserController {
    @RequestMapping({"/", "index"})
    public ModelAndView index() {
        ModelAndView mv = new ModelAndView();
        User user = new User();
        user.setId(101);
        user.setAge(23);
        user.setUsername("lisi");
        mv.setViewName("index");
        mv.addObject(user);
        return mv;
    }

    @RequestMapping("url")
    public String urlExpression(Model model) {
        model.addAttribute("name","zkx");
        model.addAttribute("age",10);
        return "url";
    }

    @RequestMapping("test")
    public @ResponseBody
    String test(String name, Integer age) {
        return "请求路径时test，参数是" + name + age;
    }

    @RequestMapping("/property")
    public String property(){
        return "property";
    }
}
